package com.epam.rd.generics;

import java.util.ArrayList;
import java.util.Collection;

public class WorkWithGenerics {

    public static <E> void fromArrayToCollection(E[] source,
            Collection<E> destination) {
        if (destination == null) {
            throw new NullPointerException();
        }
        for (E element : source) {
            destination.add(element);
        }
    }

    public static <E> void copyAll(Collection<? extends E> src,
            Collection<? super E> dest) {
        if (dest == null) {
            throw new NullPointerException();
        }
        for (E element : src) {
            dest.add(element);
        }
    }

    public static <E extends Comparable<? super E>> Collection<E>
            listOfBiggerThan(Collection<? extends E> src, E elementOfCompare) {
        Collection<E> result = new ArrayList<E>();
        if (elementOfCompare == null) {
            throw new NullPointerException();
        }
        for (E element : src) {
            if (elementOfCompare.compareTo(element) < 0) {
                result.add(element);
            }
        }
        return result;
    }

}
